import scala.io.Source

/**
  * @Author Mr.An
  * @Date 18/5/22 上午10:50
  */
object TestReduce {
//极大数据量情况下 从两个集合获取共同的元素
  def main(args: Array[String]): Unit = {
    val a=Array("a1","a2","a3")
    val b=Array("a1","a3","b2")
    val aa=Source.fromFile("/Users/finup/test/24EXPORTBUSINESSZHAIQ.txt")(scala.io.Codec.ISO8859).getLines().toStream
    val aasingle=aa.view.map(x=>(x,1)).groupBy(_._1).map(x=>{
      x._2.reduce((a,b)=>(a._1,a._2+b._2))
    })//reduce祛重
    val bb=Source.fromFile("/Users/finup/test/24EXPORTBUSINESSZHAIQ_BOR.txt")(scala.io.Codec.ISO8859).getLines().toStream
    val bbsingle=bb.view.map(x=>(x,1)).groupBy(_._1).map(x=>{
      x._2.reduce((a,b)=>(a._1,a._2+b._2))
    })   //reduce祛重
//    println(aasingle)
    bbsingle.foreach(println(_))
    println("&&"*20)
    aasingle.foreach(println)
    println("&&"*20)
    val aabbcc=aasingle.filter(x=>bbsingle.contains(x._1))
    println("&&"*20)
    aabbcc.foreach(println)
    val aintersectB = aabbcc.groupBy(_._1).filter(x=>x._2.size>1)
//    aintersectB.foreach(println)




    val a1=a.map(x=>(x,"a"))
    val b1=b.map(x=>(x,"b"))
    val ab=a1++b1
//    ab.foreach(println)
    val newab=ab.groupBy(_._1)
//    newab.foreach(x=>{x._2.foreach(println)})
    val s=Set[String]()
    val rst=newab.map(x=>(x._1,x._2.foldLeft(s)((e,f)=>e+(f._2))))
    val relrst=rst.filter(x=>x._2.size==2)
    relrst.foreach(x=>println(x._1))
    //小数据量情况下
    val aabb=a intersect b
    aabb.foreach(println)

  }

}
